﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MVVMWrapper;

namespace MVVM_Wrapper_Test {
   /// <summary>
   /// Is a View model class that wraps a Person object
   /// </summary>
   /// <remarks>
   /// The base class NotificationObject uses reflection to determine any properties that exist on this class.
   /// If the same properties exist on the business object (the wrapped object) then any Notification (INotifyPropertChanged)
   /// to those properties will be automatically propagated.
   /// 
   /// e.g. In this class we have a property called Name, the business class Person also has a property Name.
   /// when Name changes in the business layer, the business object calls NotifyPropertyChanged("Name"),
   /// because this class (PersonViewModel) also has a property Name, the base class NotificationObject will raise NotifyPropertyChanged("Name")
   /// as well. 
   /// </remarks>
   public class PersonViewModel : NotificationObject {

      private Person _person;

      public PersonViewModel(Person person)
         : base(person) {
         _person = person;
      }

      /// <summary>
      /// Gets and Sets the Name, this gets/sets the property from the business object that is wrapped
      /// </summary>
      /// <remarks>
      /// Notice how no NotifyPropertyChanged call is needed, that is all handled by the base class
      /// When the base class' property changes, because this view model object has a property of the same name
      /// the base class will reraise the NotifyPropertyChanged
      /// </remarks>
      public String Name {
         get {
            return _person.Name;
         }
         set {
            _person.Name = value;
         }
      }


      /// <summary>
      /// Gets and Sets the Age, this gets/sets the property from the business object that is wrapped
      /// </summary>
      /// <remarks>
      /// Notice how no NotifyPropertyChanged call is needed, that is all handled by the base class.
      /// When the base class' property changes, because this view model object has a property of the same name
      /// the base class will reraise the NotifyPropertyChanged
      /// </remarks>
      public int Age {
         get {
            return _person.Age;
         }
         set {
            _person.Age = value;
         }
      }


      private Boolean _isSelected;

      /// <summary>
      /// Gets and sets the IsSelected property
      /// </summary>
      public Boolean IsSelected {
         get { return _isSelected; }
         set {
            if (_isSelected == value) { }
            else {
               _isSelected = value;
               NotifyPropertyChanged("IsSelected");
            }
         }
      }
   }
}
